﻿using FireUI.Core.TLManager;
using Prism.Commands;
using Prism.Mvvm;
using System.Collections.Generic;
using System.Linq;

namespace FireUI.Windows.ViewModels;

public class ThemeLanViewModel : BindableBase
{
    private readonly ITLManager _themeManager;
    private readonly ITLManager _lanManager;

    public DelegateCommand<object> ApplyThemeCommand { get; protected set; }
    public DelegateCommand<object> ApplyLanguageCommand { get; protected set; }

    public ThemeLanViewModel(IEnumerable<ITLManager> tLManagers)
    {
        ApplyThemeCommand = new DelegateCommand<object>(ApplyThemeExcute);
        ApplyLanguageCommand = new DelegateCommand<object>(ApplyLanguageExcute);
        _themeManager = tLManagers.ElementAt(0);
        _lanManager = tLManagers.ElementAt(1);
    }

    private void ApplyThemeExcute(object para)
    {
        var ischecked = (bool)para;
        var names = _themeManager.GetNames();
        _themeManager.Apply(ischecked ? names.ElementAt(1) : names.ElementAt(0));
    }

    private void ApplyLanguageExcute(object para)
    {
        var ischecked = (bool)para;
        var names = _lanManager.GetNames();
        _lanManager.Apply(ischecked ? names.ElementAt(0) : names.ElementAt(1));
    }
}